{include file="public/header"}
<!-- 公共样式 结束 -->
<style>
    .layui-table img {
        max-width: none;
    }
</style>
</head>

<body>
    <div class="cBody">
        <div class="console">
            <a class="layui-btn layui-btn-primary" onclick="window.location.href = '{:url('dbd/dbdlist')}';">数据表</a>
            <a class="layui-btn" onclick="OpenView('{:url('dbd/fieldadd')}?table={$table}','添加字段')">添加字段</a>
        </div>
        <table id="demo" lay-filter="test"></table>
    </div>
</body>
<script type="text/html" id="barDemo">
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
    layui.use(['table', 'layer'], function () {
        var table = layui.table;
        var layer = layui.layer;
        //第一个实例
        var datatable = table.render({
            url: '?table={$table}',
            elem: '#demo'
            , cols: [[ //表头
                { field: 'Field', title: '字段名', sort: true },
                { field: 'Type', title: '类型(长度)', sort: true },
                { field: 'Null', title: '是否为空', sort: true },
                { field: 'Key', title: '主键', sort: true },
                { field: 'Default', title: '默认', sort: true },
                { field: 'Comment', title: '字段注释', sort: false },
                { field: 'right', title: '操作', toolbar: "#barDemo", fixed: 'right' }
            ]]
        });
        //监听工具条
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('删除了无法恢复的哦！确定吗？', function (index) {
                    // console.log(data);
                    $.ajax({
                        url: '{:url('dbd/fielddel')}?name=' + data.Field + "&table={$table}",
                        dataType: 'json',
                        type: 'GET',
                        success: function (res) {
                            console.log(res);
                            if (res.code == 0) {
                                obj.del();
                                layer.close(index);
                            } else {
                                layer.msg(res.msg, {
                                    icon: 2
                                });
                            }
                        }, error: function () {
                            layer.msg('网络出错，请联系客服！', {
                                icon: 0
                            });
                        }
                    });
                });
            }
        });
    });
    
</script>
{include file="public/footer"}